﻿@using System.Data
@using RBS.Common
@model RBS.Web.Hotel.Models.Order.OrderViewModel
@{
    ViewBag.Title = Model.SeateName;
     Layout = "~/Views/Shared/_Layout.cshtml"; 
}
<link href="~/Content/default/jiesuan.css" rel="stylesheet" /> 

<div class="line5"></div>
@using (Ajax.BeginForm("jiesuan", null, new AjaxOptions { OnSuccess = "OnSuccess" }, new { @id = "jiesuan" }))
{  
    @Html.HiddenFor(model => model.OrderModel.Id);
    @Html.HiddenFor(model => model.OrderModel.H_Id);
    @Html.HiddenFor(model => model.OrderModel.DineTable);
    @Html.HiddenFor(model => model.OrderModel.U_Id); 
    @Html.HiddenFor(model => model.UserIntegration);  
    <table class="ltable">
        <tr>
            <td>结帐单号：@Html.DisplayFor(model => model.Number)</td>
            <td>结账台号：@Model.SeateName</td>
        </tr>
    </table> 
    <div class="line5"></div>
    <table class="ltable">
        <tr>
            <td>消费金额：@(string.Format("{0:N1}", Model.OrderModel.OrderAmount)) </td>
            <td>就餐人数：  @Html.TextBoxFor(model => model.OrderModel.DineNum, null, new { @class = "input small" }) 人</td>
        </tr>
    </table>
    <div class="line5"></div> 
    <table class="ltable">
        <tr>
            <td>会员编号/姓名：  @Html.DisplayFor(model => model.User.U_Name)</td>
            <td>会员积分：@Model.UserIntegration （可抵用 @String.Format("{0}", Model.UserIntegration / 100.00) 元）</td>
        </tr>
    </table>
    <div class="content-tab-wrap">
        <div id="floatHead" class="content-tab">
            <div class="content-tab-ul-wrap">
                <ul>
                    <li><a href="javascript:;" onclick="tabs(this);" class="selected">结算金额</a></li>

                    <li><a href="javascript:;" onclick="tabs(this);">订单详情</a></li>
                </ul>
            </div>
        </div>
    </div> 
    <div class="clear"></div> 
    <div class="tab-content tab-content1">
        <dl>
            <dt>支付方式：</dt>
            <dd>
                <div class="rule-single-select">
                    @Html.DropDownListFor(model => model.Seetlement.PayType,
                                                          new[] { new SelectListItem() { Text = "现金", Value = "现金" }, 
                                                              new SelectListItem() { Text = "刷卡", Value = "刷卡" },
                                                          })
                </div>
            </dd>
        </dl>
        <dl>
            <dt>消费金额：</dt>
            <dd>@Html.TextBoxFor(model => model.Seetlement.OrderAmount, string.Format("{0:N1}", Model.Seetlement.OrderAmount), new { @class = "input small jine", @readonly = "readonly" })元</dd>
        </dl>
        @{
                                                   if (Model.User != null)
                                                   {
            <dl>
                <dt>积分抵扣：</dt>
                <dd>@Html.TextBoxFor(model => model.Seetlement.JF, "0", new { @class = "input small jine", @readonly = "readonly" }) 分 </dd>
            </dl>
          @*  <dl>
                <dt>广告券：</dt>
                <dd>@Html.TextBoxFor(model => model.Seetlement.Advertis, "0", new { @class = "input small jine" }) 元 </dd>
            </dl>
            <dl>
                <dt>消费券：</dt>
                <dd>@Html.TextBoxFor(model => model.Seetlement.Consumption, "0", new { @class = "input small jine" }) 元 </dd>
            </dl>*@
@* <dl>
                                                           <dt>优惠券抵扣：</dt>
                                                           <dd>@Html.TextBoxFor(model => model.Seetlement.SendFood, "0", new { @class = "input small jine" }) 元 </dd>  
                                                       </dl>*@
            
@*<dl>
                <dt>优惠券使用：</dt>
                <dd>
                    @Html.HiddenFor(model => model.Seetlement.AdvertisId) 
                    @{ 
                        <ul>
                            @if (Model.UserDeed == null)
                            {
                                <li>无优惠卷信息</li>
                            }
                            else
                            {
                            foreach (var row in Model.UserDeed)
                            { 
                                if(row.DeedType==1){
                                    <li> 
                                        <input id="@row.Id" type="checkbox"  name="SendFood" datatype="max2" value="@row.Id" /> 
                                        <label for="@row.Id">@row.Crowd [送采券]</label> 
                                    </li>
                                }
                                if (row.DeedType == 2)
                                {
                                <li> 
                                <input id="@row.Id" type="checkbox"  name="Consumption" datatype="max2" value="@row.Id" /> 
                                <label for="@row.Id">@row.Crowd  [消费券]</label> 
                                </li>  }
                                if (row.DeedType == 3)
                                {
                                <li> 
                                <input id="@row.Id" type="checkbox"  name="Advertis" datatype="max2" value="@row.Id" /> 
                                <label for="@row.Id">@row.Crowd  [广告券]</label> 
                                </li>  }
                              }
                            } 
                        </ul>
                    } 
                </dd>
            </dl> *@
                                                   }  
            <script>
                $(function () {
                    //用户积分
                    $('#Seetlement_JF').change(function () {
                        var a = $("#Seetlement_OrderAmount").val();
                        var userIntegration = $("#UserIntegration").val();
                        //alert(userIntegration);
                        var b = $(this).val();
                        var aa = a * 100;
                        if (parseInt(b) > parseInt(userIntegration)) {
                            alert("您当前积分为：" + userIntegration);
                            $(this).val(userIntegration);
                        }
                        if (b > aa) {
                            alert("积分最大输入为：" + aa);
                            $(this).val(aa);
                        }
                        $("#Seetlement_Amount").focus();
                    });
                    //用户优惠券
                    /* $(':checkbox[name="chkItem"]').click(function() {
                         $("#Seetlement_Amount").focus();
                     });*/
                    $("#Seetlement_Amount").focus(function () {
                        var theOrderAmount = $("#Seetlement_OrderAmount").val();
                        var ccccc = 0;
                        if ($('#Seetlement_JF').length > 0) {
                            ccccc = parseFloat($('#Seetlement_JF').val()) / 100;
                        }
                        var youhuiquan = 0;
                        if ($("#Seetlement_Advertis").length > 0) {
                            alert(1);
                            var youhuiquan1 = parseFloat($('#Seetlement_Advertis').val());
                            youhuiquan += youhuiquan1;
                        }
                        if ($("#Seetlement_Consumption").length > 0) {
                            var youhuiquan2 = parseFloat($('#Seetlement_Consumption').val());
                            youhuiquan += youhuiquan2;
                        }
                        /* for (var i = 0; i < this.form.chkItem.length; i++) {
                             if (this.form.chkItem[i].type == 'checkbox') {
                                 if (this.form.chkItem[i].checked) {
                                     youhuiquan += parseFloat(this.form.chkItem[i].value);
                                 }
                             }
                         }*/
                        this.value = parseFloat(theOrderAmount) - ccccc - youhuiquan;
                        $("#Seetlement_PaidAmount").focus();
                    });

                    //优惠金额输入后
                    $('#Seetlement_DisAmount').change(function () { 
                        $("#Seetlement_RecAmount").focus();
                    });

                    $("#Seetlement_RecAmount").focus(function () {
                        var amount = parseFloat($("#Seetlement_Amount").val());
                        var disAmount = parseFloat($("#Seetlement_DisAmount").val());
                        var aaa = amount - disAmount;
                        if (aaa < 0) {
                            alert("优惠金额不能大于应付金额");
                            $('#Seetlement_DisAmount').focus();
                        } else {
                            $("#Seetlement_PaidAmount").val(amount - disAmount);
                        }
                      
                       // this.value = amount - disAmount;
                       // $("#Seetlement_GiveAmount").focus();
                    });
                    
                    $('#Seetlement_RecAmount').change(function () {
                        $("#Seetlement_GiveAmount").focus();
                    });
                    $("#Seetlement_GiveAmount").focus(function () {
                        var paidAmount = parseFloat($("#Seetlement_PaidAmount").val());
                        var recAmount = parseFloat($("#Seetlement_RecAmount").val());
                        this.value = (recAmount - paidAmount).toFixed(2);
                    });
              
                });
            </script>
       
        }
        <dl>
            <dt>应付金额：</dt>
            <dd>@Html.TextBoxFor(model => model.Seetlement.Amount, string.Format("{0:N1}", Model.Seetlement.OrderAmount), new { @class = "input small jine", @readonly = "readonly" })元
            </dd>
        </dl>
        <dl>
            <dt>优惠金额：</dt> @*, onfocus="javascript:this.value='0'"*@
            <dd>@Html.TextBoxFor(model => model.Seetlement.DisAmount, "0", new { @class = "input small jine", datatype = "ck", errormsg = "金额错误", sucmsg = " ", nullmsg="请输入优惠金额，如果不优惠则填写0！" }) 元</dd>

        </dl>
        <dl>
            <dt>应收金额：</dt>
            <dd>@Html.TextBoxFor(model => model.Seetlement.PaidAmount, string.Format("{0:N1}", Model.Seetlement.OrderAmount), new { @class = "input small jine", @readonly = "readonly", datatype = "ck", errormsg = "金额错误", sucmsg = " " })元</dd>
        </dl>
        <dl>
            <dt>实收金额：</dt>
            <dd>@Html.TextBoxFor(model => model.Seetlement.RecAmount, null, new { @class = "input small jine", datatype = "ck", errormsg = "金额错误", sucmsg = " " , nullmsg="请输入实收金额", onfocus="javascript:this.value=''"  })元</dd>
        </dl>
        <dl>
            <dt>现金找零：</dt>
            <dd>@Html.TextBoxFor(model => model.Seetlement.GiveAmount, null, new { @class = "input small jine", datatype = "ck", @readonly = "readonly", errormsg = "找零不能小于零元", sucmsg = " " })元</dd>
        </dl>
        @{
           if (Model.HotelDeed!=null && Model.User != null)
          {
            <dl>
                <dt>店铺优惠券：</dt>
                <dd>
                    <ul>
                        @foreach (var row in Model.HotelDeed)
                        {
                            <li>
                                <input id="@row.Id" type="checkbox"  name="HotelDeedCKB" value="@row.Id" />
                                <label for="@row.Id">@row.Crowd </label>
                            </li>    
                        }
                    </ul>
                </dd>
            </dl> 
                                                   } 
        }

        <div class="line10"></div> 
        @{
         if (ViewBag.Isedit)
            {
                    <div class="btn-list">
                      <input type="submit" value="结账" id="btnjiesuan" class="btn" />
                    </div>
            }
        } 
    </div>   
    <div class="tab-content tab-content1" style="display: none">
        <table class="ltable">
            <tr>
                <td></td>
                <td>商品名称</td>
                <td>单价</td>
                <td>数量</td>
                <td>金额</td>
            </tr>
            @if (null != ViewData.Model.OrderDetailsModel)
            {
                foreach (var item in ViewData.Model.OrderDetailsModel)
                {
                <tr>
                    <td>&nbsp;</td>
                    <td>@item.CName</td>
                    <td>@item.DisAmount</td>
                    <td>@{
                         
                        @Html.Raw(string.Format("{0:N1}", item.Num * item.Weight))   
                    if (ViewBag.Isedit == true && item.IsDisplay=="1")
                    {
                        <img src="@Url.Content("~/Content/EasyUI/themes/icons/pencil.png")" onclick="editNum(@item.OrderId,@item.HCId,@item.Num*@item.Weight)"/>
                    } 
                    }
                    </td>
                    <td>@(string.Format("{0:N1}", item.DisAmount * item.Num * item.Weight))</td>
                </tr>
                }
                
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td>合计金额</td>
                    <td>@Html.DisplayFor(model => model.Seetlement.OrderAmount, string.Format("{0:N1}", Model.Seetlement.OrderAmount))</td>
                </tr>
            }
        </table>
    </div> 
       
    <script>
        $(function () { 
            $("#jiesuan").Validform({
                tiptype: 4
            });
            $.extend($.Datatype, {
                "ck": function (gets, obj, curform, regxp) {
                    var reg1 = /^-?(([0-9]\d*)(\.\d{1,2})?)$|(0\.0?([0-9]\d?))$/;
                    if (isNaN(gets)) {
                        return false;
                    }
                    if (gets.length == 0) {
                        return false;
                    }
                    if (!reg1.test(gets)) { return false; }
                    if (parseInt(gets) < 0) {
                        return false;
                    }
                    return true;
                },
                "max2": function (gets, obj, curform, regxp) {
                    var atmax = 1,
                        numselected = curform.find("input[name='" + obj.attr("name") + "']:checked").length;

                    if (numselected > atmax) {
                        return "每种优惠券最多只能选择" + atmax + "项！";
                    }
                    return true;
                }
            });
        });
        function editNum(oid, cid, c) {
            var obj = new Object();
            obj.Oid = oid;
            obj.Cid = cid;
            obj.Num = c;
            $.dialog({
                id: 'editNumAlert',
                title: "修改份量",
                width: 200,
                height: 100,
                content: 'url:@Url.Action("UpdateNum")',
                data: obj
            });

        }
        var isok = false;
        function OnSuccess(ret) {
            if (ret.IsSuccess) {
                $.dialog.tips(ret.Msg, function () {
                    window.location.href = ret.Data;
                });
            } else {
                $.dialog.alert(ret.Msg);
                return false;
            }
        }
    </script> 
   
}